//
//  ZyUI.swift
//  swift各类控件集锦
//
//  Created by iosdev1 on 2016/12/30.
//  Copyright © 2016年 zyy. All rights reserved.
//

import Foundation
import UIKit


///渐隐弹出框，提示
///
/// - Parameters:
///   - message: 文字
func zyUIshowMessage(message:String)  {
    if message.isEmpty||message == "" {
        return;
    }
    
    let window:UIWindow = UIApplication.shared.keyWindow!;
    let showview:UIView = UIView.init()
    showview.alpha = 1.0
    showview.layer.masksToBounds = true
    showview.layer.cornerRadius = 5.0
//    showview.backgroundColor = UIColor.init(red: 0.5, green: 0.5, blue: 0.5, alpha: 0.5)
    showview.backgroundColor = UIColor.init(colorLiteralRed: 0.5, green: 0.5, blue: 0.5, alpha: 0.5)
    window.addSubview(showview)
    
    let label:UILabel = UILabel.init()
    label.text = message;
    label.font = UIFont.systemFont(ofSize: 14.0)

    let width:CGFloat = zyUtilsgetContentSizeWidthFont(content: message, heightContent: 17, font: 17)
    label.frame = CGRect(x:10, y:5, width:width, height:20)
    showview.addSubview(label)
    showview.frame = CGRect(x:(WIDTH_SCREEN - width - 20)/2, y:HEIGHT_SCREEN/2, width:width+20, height:30);
    
    UIView.animate(withDuration: 3, animations: {
        showview.alpha = 0
    }) { (true) in
        showview.removeFromSuperview()
    }
}

func zyUIlblInitWith(title:String, font:CGFloat, color:UIColor, bgColor:UIColor) -> UILabel {
    let lbl:UILabel = UILabel.init()
    lbl.text = title
    lbl.font = UIFont.systemFont(ofSize: font)
    lbl.textColor = color
    lbl.backgroundColor = bgColor
    return lbl
}

